<?php
//购物车控制器
class Controller_Admin_Cart extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type        = 'userCart';
        $this->_no_buttons       = TRUE;
        $this->_no_list_actions  = TRUE;
        $this->_list_pagesize    = 0;
        $this->_pagination_type  = 'query_string';
        $this->_pagination_param = 'page';

        parent::__construct($req, $res);

        $this->_list_where = array(
        );

        $this->_sort_extra_columns = array(
            array('changed', DB::expr('curdate()')),
        );
    }

	//默认首页
    public function action_index ()
    {
        $this->action_list();
    }

	//购物车首页
    public function action_list ($uid = 0)
    {
        $this->_list_where = array(
            array('uid', '=', $uid),
        );

        $page = $this->request->query('page');
        $page = max(1, $page);

        parent::action_list();
    }

	//数据结构修改
    public function list_filter_data (& $rows)
    {
        $uid = $this->_list_where[0][2];
        $userName = User::getUserFromUid($uid)->getUserName();

        $goodsList = array();

        foreach ($rows as $rs)
        {
            $shopName = $rs['shop']['shopName'];
            $shopId   = $rs['shop']['shopId'];
            foreach ($rs['goods'] as $goods)
            {
                $goods['shopId'] = $shopId;
                $goods['shopName'] = $shopName;
                $goods['userName'] = $userName;
                $name = $goods['name'];
                $attr = $goods['attr']['desc'];
                $goods['goodsDesc'] = "$name<br/>\n$attr";
                $goods['money'] = "￥".number_format($goods['money']['money']/100, 2);
            }

            $goodsList[] = $goods;
        }

        $rows = $goodsList;
    }


    public function actions_by_list_row (& $row, & $menus)
    {
    }

	//
    public function list_get_data ($offset, $limit)
    {
        $uid = $this->_list_where[0][2];
        $user = User::getUserFromUid($uid);
        return App_Cart::detailList($user);
    }
}
